package com.alipay.service;

import cn.hutool.core.util.IdUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.mapper.BusinessInfoMapper;
import com.alipay.mapper.UserInfoMapper;
import com.alipay.pojo.BusinessInfo;
import com.alipay.pojo.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xn
 * @date 2023/5/3 12:03
 */
@Service
public class PayService {
    @Resource
    UserInfoMapper userInfoMapper;
    @Resource
    BusinessInfoMapper businessInfoMapper;

    public boolean test1(String m, String total_amount) {
        Integer userId = Integer.valueOf(m);
        System.out.println(userId);
        System.out.println(userInfoMapper);
        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
        System.out.println("userInfo");
        System.out.println(userInfo);
        System.out.println("userInfo");
        //更新账号余额
        int i = userInfoMapper.updateByPrimaryKeySelective(new UserInfo(
                userId, null, null, null, null,
                userInfo.getBalance() + Double.valueOf(total_amount), null, null, null
        ));

        if (i == 1) {
            return true;
        }
        return false;
    }

    public boolean test2(String ID, String total_amount) {

        BusinessInfo businessInfo = businessInfoMapper.selectByPrimaryKey(Integer.parseInt(ID));
        double value = businessInfo.getBalance() - Double.valueOf(total_amount);
        if (value < 0) {
            return false;
        }
        businessInfo.setBalance(value);
        businessInfoMapper.updateByPrimaryKeySelective(businessInfo);
        return true;
    }
}
